package com.mryao.gxkygl.common.exception.Handler;

import com.mryao.gxkygl.common.result.Result;
import org.hibernate.exception.ConstraintViolationException;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletResponse;
@Component
public class DataIntegrityViolationExceptionHandler implements ExceptionHandler{
    @Override
    public Object handler(HttpServletResponse response, Throwable e) {
        if(e instanceof DataIntegrityViolationException){
            return  Result.getError("数据重复！！");
        }
        return null;
    }
}
